<!DOCTYPE html>
<html lang="zh-CN" dir="ltr">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Vector(a, b) | JS工具包</title>
    <meta name="description" content="简单、小巧、快捷">
    <meta name="generator" content="VitePress v1.4.3">
    <link rel="preload stylesheet" href="/toolkit_js/assets/style.rMvErsXa.css" as="style">
    
    <script type="module" src="/toolkit_js/assets/app.-Ce8BA_t.js"></script>
    <link rel="preload" href="/toolkit_js/assets/inter-roman-latin.Di8DUHzh.woff2" as="font" type="font/woff2" crossorigin="">
    <link rel="modulepreload" href="/toolkit_js/assets/chunks/theme.DXmyu1pJ.js">
    <link rel="modulepreload" href="/toolkit_js/assets/chunks/framework.Co0xru0F.js">
    <link rel="modulepreload" href="/toolkit_js/assets/class_Vector_index.md.Dd4O8dJl.lean.js">
    <script id="check-dark-mode">(()=>{const e=localStorage.getItem("vitepress-theme-appearance")||"auto",a=window.matchMedia("(prefers-color-scheme: dark)").matches;(!e||e==="auto"?a:e==="dark")&&document.documentElement.classList.add("dark")})();</script>
    <script id="check-mac-os">document.documentElement.classList.toggle("mac",/Mac|iPhone|iPod|iPad/i.test(navigator.platform));</script>
  </head>
  <body>
    <div id="app"><div class="Layout" data-v-d8b57b2d><!--[--><!--]--><!--[--><span tabindex="-1" data-v-c8291ffa></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-c8291ffa> Skip to content </a><!--]--><!----><header class="VPNav" data-v-d8b57b2d data-v-7ad780c2><div class="VPNavBar" data-v-7ad780c2 data-v-9fd4d1dd><div class="wrapper" data-v-9fd4d1dd><div class="container" data-v-9fd4d1dd><div class="title" data-v-9fd4d1dd><div class="VPNavBarTitle has-sidebar" data-v-9fd4d1dd data-v-9f43907a><a class="title" href="/toolkit_js/" data-v-9f43907a><!--[--><!--]--><!----><span data-v-9f43907a>JS工具包</span><!--[--><!--]--></a></div></div><div class="content" data-v-9fd4d1dd><div class="content-body" data-v-9fd4d1dd><!--[--><!--]--><div class="VPNavBarSearch search" data-v-9fd4d1dd><!--[--><!----><div id="local-search"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><span class="vp-icon DocSearch-Search-Icon"></span><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"><kbd class="DocSearch-Button-Key"></kbd><kbd class="DocSearch-Button-Key">K</kbd></span></button></div><!--]--></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-9fd4d1dd data-v-afb2845e><span id="main-nav-aria-label" class="visually-hidden" data-v-afb2845e> Main Navigation </span><!--[--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/toolkit_js/md/quick-start.html" tabindex="0" data-v-afb2845e data-v-815115f5><!--[--><span data-v-815115f5>快速开始</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/toolkit_js/fn/curry.html" tabindex="0" data-v-afb2845e data-v-815115f5><!--[--><span data-v-815115f5>Function</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/toolkit_js/class/Vector.html" tabindex="0" data-v-afb2845e data-v-815115f5><!--[--><span data-v-815115f5>Class</span><!--]--></a><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-9fd4d1dd data-v-3f90c1a5><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title aria-checked="false" data-v-3f90c1a5 data-v-be9742d9 data-v-b4ccac88><span class="check" data-v-b4ccac88><span class="icon" data-v-b4ccac88><!--[--><span class="vpi-sun sun" data-v-be9742d9></span><span class="vpi-moon moon" data-v-be9742d9></span><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-9fd4d1dd data-v-ef6192dc data-v-e71e869c><!--[--><a class="VPSocialLink no-icon" href="https://github.com/varcat/toolkit_js" aria-label="github" target="_blank" rel="noopener" data-v-e71e869c data-v-358b6670><span class="vpi-social-github" /></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-9fd4d1dd data-v-f953d92f data-v-bfe7971f><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-bfe7971f><span class="vpi-more-horizontal icon" data-v-bfe7971f></span></button><div class="menu" data-v-bfe7971f><div class="VPMenu" data-v-bfe7971f data-v-20ed86d6><!----><!--[--><!--[--><!----><div class="group" data-v-f953d92f><div class="item appearance" data-v-f953d92f><p class="label" data-v-f953d92f>Appearance</p><div class="appearance-action" data-v-f953d92f><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title aria-checked="false" data-v-f953d92f data-v-be9742d9 data-v-b4ccac88><span class="check" data-v-b4ccac88><span class="icon" data-v-b4ccac88><!--[--><span class="vpi-sun sun" data-v-be9742d9></span><span class="vpi-moon moon" data-v-be9742d9></span><!--]--></span></span></button></div></div></div><div class="group" data-v-f953d92f><div class="item social-links" data-v-f953d92f><div class="VPSocialLinks social-links-list" data-v-f953d92f data-v-e71e869c><!--[--><a class="VPSocialLink no-icon" href="https://github.com/varcat/toolkit_js" aria-label="github" target="_blank" rel="noopener" data-v-e71e869c data-v-358b6670><span class="vpi-social-github" /></a><!--]--></div></div></div><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-9fd4d1dd data-v-6bee1efd><span class="container" data-v-6bee1efd><span class="top" data-v-6bee1efd></span><span class="middle" data-v-6bee1efd></span><span class="bottom" data-v-6bee1efd></span></span></button></div></div></div></div><div class="divider" data-v-9fd4d1dd><div class="divider-line" data-v-9fd4d1dd></div></div></div><!----></header><div class="VPLocalNav has-sidebar empty" data-v-d8b57b2d data-v-2488c25a><div class="container" data-v-2488c25a><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-2488c25a><span class="vpi-align-left menu-icon" data-v-2488c25a></span><span class="menu-text" data-v-2488c25a>Menu</span></button><div class="VPLocalNavOutlineDropdown" style="--vp-vh:0px;" data-v-2488c25a data-v-883964e0><button data-v-883964e0>Return to top</button><!----></div></div></div><aside class="VPSidebar" data-v-d8b57b2d data-v-42c4c606><div class="curtain" data-v-42c4c606></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-42c4c606><span class="visually-hidden" id="sidebar-aria-label" data-v-42c4c606> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="no-transition group" data-v-51288d80><section class="VPSidebarItem level-0 has-active" data-v-51288d80 data-v-edd2eed8><!----><div class="items" data-v-edd2eed8><!--[--><div class="VPSidebarItem level-1 is-link" data-v-edd2eed8 data-v-edd2eed8><div class="item" data-v-edd2eed8><div class="indicator" data-v-edd2eed8></div><a class="VPLink link link" href="/toolkit_js/class/Vector/" data-v-edd2eed8><!--[--><p class="text" data-v-edd2eed8>Vector</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><!--]--><!--[--><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-d8b57b2d data-v-9a6c75ad><div class="VPDoc has-sidebar has-aside" data-v-9a6c75ad data-v-e6f2a212><!--[--><!--]--><div class="container" data-v-e6f2a212><div class="aside" data-v-e6f2a212><div class="aside-curtain" data-v-e6f2a212></div><div class="aside-container" data-v-e6f2a212><div class="aside-content" data-v-e6f2a212><div class="VPDocAside" data-v-e6f2a212 data-v-cb998dce><!--[--><!--]--><!--[--><!--]--><nav aria-labelledby="doc-outline-aria-label" class="VPDocAsideOutline" data-v-cb998dce data-v-f610f197><div class="content" data-v-f610f197><div class="outline-marker" data-v-f610f197></div><div aria-level="2" class="outline-title" id="doc-outline-aria-label" role="heading" data-v-f610f197>On this page</div><ul class="VPDocOutlineItem root" data-v-f610f197 data-v-53c99d69><!--[--><!--]--></ul></div></nav><!--[--><!--]--><div class="spacer" data-v-cb998dce></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-e6f2a212><div class="content-container" data-v-e6f2a212><!--[--><!--]--><main class="main" data-v-e6f2a212><div style="position:relative;" class="vp-doc _toolkit_js_class_Vector_" data-v-e6f2a212><div><h1 id="vector-a-b" tabindex="-1">Vector(a, b) <a class="header-anchor" href="#vector-a-b" aria-label="Permalink to &quot;Vector(a, b)&quot;">​</a></h1><p>可用于判断手势动作等</p><p>另参考 <a href="/toolkit_js/fn/getPoint/">getPoint</a></p><h2 id="入参" tabindex="-1">入参 <a class="header-anchor" href="#入参" aria-label="Permalink to &quot;入参&quot;">​</a></h2><table tabindex="0"><thead><tr><th style="text-align:left;">参数</th><th style="text-align:left;">类型</th><th style="text-align:left;">必填</th><th style="text-align:left;">说明</th></tr></thead><tbody><tr><td style="text-align:left;">a</td><td style="text-align:left;">Point</td><td style="text-align:left;">是</td><td style="text-align:left;">-</td></tr><tr><td style="text-align:left;">b</td><td style="text-align:left;">Point</td><td style="text-align:left;">否</td><td style="text-align:left;">默认为 <code>{x: 0, y: 0}</code></td></tr></tbody></table><div class="language-ts vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">ts</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">export</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> interface</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Point</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">  x</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> number</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">  y</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> number</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><h2 id="示例" tabindex="-1">示例 <a class="header-anchor" href="#示例" aria-label="Permalink to &quot;示例&quot;">​</a></h2><h3 id="构造方式" tabindex="-1">构造方式 <a class="header-anchor" href="#构造方式" aria-label="Permalink to &quot;构造方式&quot;">​</a></h3><div class="language-typescript vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">typescript</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { Vector } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">from</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;wsp-toolkit&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 两种构造 Vector 的方式</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> v1</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> new</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Vector</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">({ x: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, y: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> });</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> v2</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Vector.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">of</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">({ x: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, y: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> });</span></span></code></pre></div><h3 id="pinch-双指缩放" tabindex="-1">Pinch(双指缩放) <a class="header-anchor" href="#pinch-双指缩放" aria-label="Permalink to &quot;Pinch(双指缩放)&quot;">​</a></h3><p><img src="/toolkit_js/assets/img_1.bRIF1A_Y.png" alt="img_1.png"></p><div class="language-ts vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">ts</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 省略获取Point的代码</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> a</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> new</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Vector</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(aPoint1, aPoint2);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> b</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Vector.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">of</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(bPoint1, bPoint2);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">a.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">getScale</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(b); </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// a 放大到 b 的倍率</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">b.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">getScale</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(a); </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// b 缩小到 a 的倍率</span></span></code></pre></div><h3 id="rotate-双指旋转" tabindex="-1">Rotate(双指旋转) <a class="header-anchor" href="#rotate-双指旋转" aria-label="Permalink to &quot;Rotate(双指旋转)&quot;">​</a></h3><p><img src="/toolkit_js/assets/img_2.BpMn9eEG.png" alt="img_2.png"></p><div class="language-typescript vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">typescript</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 省略获取Point的代码</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> a</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> new</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Vector</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(aPoint1, aPoint2);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> b</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Vector.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">of</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(bPoint1, bPoint2);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">a.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">getAngle</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(b); </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// a 顺时针旋转到 b</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">b.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">getAngle</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(a); </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// b 逆时针旋转到 a</span></span></code></pre></div><h3 id="singlepinch-单指缩放" tabindex="-1">singlePinch(单指缩放) <a class="header-anchor" href="#singlepinch-单指缩放" aria-label="Permalink to &quot;singlePinch(单指缩放)&quot;">​</a></h3><p><img src="/toolkit_js/assets/img.KpS_NekW.png" alt="img.png"></p><div class="language-ts vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">ts</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 依赖基准点(正方形中间的点)进行计算, 假定值为</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { Vector } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">from</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;./Vector&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> basePoint</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { x: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, y: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> };</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 计算 touchstart 向量模</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> a</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> new</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Vector</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(startPoint, basePoint);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 计算 touchend（touchmove相同操作） 向量模</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> b</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> new</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Vector</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(currentPoint, basePoint);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">a.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">getScale</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(b); </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// a 放大到 b 的倍率</span></span></code></pre></div><h3 id="singlerotate-单指旋转" tabindex="-1">singleRotate(单指旋转) <a class="header-anchor" href="#singlerotate-单指旋转" aria-label="Permalink to &quot;singleRotate(单指旋转)&quot;">​</a></h3><p><img src="/toolkit_js/assets/img_3.CTZXqetX.png" alt="img_3.png"></p><div class="language-ts vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">ts</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 依然需要依赖基准点进行计算</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> a</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> new</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Vector</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(startPoint, basePoint);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> b</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Vector</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(currentPoint, basePoint);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">a.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">getAngle</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(b); </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 计算a旋转到b的角度</span></span></code></pre></div></div></div></main><footer class="VPDocFooter" data-v-e6f2a212 data-v-1bcd8184><!--[--><!--]--><div class="edit-info" data-v-1bcd8184><!----><div class="last-updated" data-v-1bcd8184><p class="VPLastUpdated" data-v-1bcd8184 data-v-1bb0c8a8>Last updated: <time datetime="2024-11-07T06:11:16.000Z" data-v-1bb0c8a8></time></p></div></div><!----></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><!----><!--[--><!--]--></div></div>
    <script>window.__VP_HASH_MAP__=JSON.parse("{\"class_vector_index.md\":\"Dd4O8dJl\",\"fn_and_index.md\":\"Bl9Yi-cw\",\"fn_at_index.md\":\"BxvSycLZ\",\"fn_clamp_index.md\":\"D9UwpYCr\",\"fn_concatmap_index.md\":\"CqDf_XwW\",\"fn_curry_index.md\":\"DStGfa2a\",\"fn_debounce_index.md\":\"DGrwyVIZ\",\"fn_decimallength_index.md\":\"BBN2xhsk\",\"fn_getpoint_index.md\":\"fhZQkc_-\",\"fn_identity_index.md\":\"C-5uSmr4\",\"fn_ifelse_index.md\":\"BWuY8EN6\",\"fn_isempty_index.md\":\"dIhGsSJi\",\"fn_isexist_index.md\":\"DdWLaBkF\",\"fn_isiterable_index.md\":\"CYzmAfZA\",\"fn_isnil_index.md\":\"ByOWq-7t\",\"fn_issafenum_index.md\":\"DdMKbkwo\",\"fn_iterative_index.md\":\"DeB-WP9K\",\"fn_last_index.md\":\"CdnoSU9Q\",\"fn_matrixto_index.md\":\"DvIL3g5m\",\"fn_once_index.md\":\"B9gCXFEM\",\"fn_or_index.md\":\"C6bVN6qe\",\"fn_pipe_index.md\":\"DR9NC9FI\",\"fn_promisetry_index.md\":\"BpSrAnhX\",\"fn_prop_index.md\":\"DomPIUDA\",\"fn_sleep_index.md\":\"MpajAF14\",\"fn_splitintegerdecimal_index.md\":\"PNQtnk9Z\",\"fn_throttle_index.md\":\"DT-gPLSL\",\"fn_toarray_index.md\":\"Ce05JLTZ\",\"fn_toggle_index.md\":\"BEebwzbr\",\"fn_tonumberstr_index.md\":\"DuJq8OFr\",\"fn_topromisetuple_index.md\":\"Ba9_u9Ry\",\"fn_treeeach_index.md\":\"BGztJ4og\",\"fn_typeof_index.md\":\"8VbTxz6X\",\"fn_unique_index.md\":\"BhfMNhCc\",\"fn_zip_index.md\":\"CUeqtRh4\",\"fn_zipwith_index.md\":\"BN9t3wPD\",\"index.md\":\"Dtyu0DKr\",\"md_quick-start.md\":\"2747pSrg\",\"readme.md\":\"CeIJBcfz\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"zh-CN\",\"dir\":\"ltr\",\"title\":\"JS工具包\",\"description\":\"简单、小巧、快捷\",\"base\":\"/toolkit_js/\",\"head\":[],\"router\":{\"prefetchLinks\":true},\"appearance\":true,\"themeConfig\":{\"search\":{\"provider\":\"local\"},\"nav\":[{\"text\":\"快速开始\",\"link\":\"/md/quick-start\"},{\"text\":\"Function\",\"link\":\"/fn/curry\"},{\"text\":\"Class\",\"link\":\"/class/Vector\"}],\"sidebar\":{\"/class/\":[{\"text\":\"Vector\",\"link\":\"/class/Vector/\"}],\"/fn/\":[{\"text\":\"Function\",\"collapsed\":false,\"items\":[{\"text\":\"curry\",\"link\":\"/fn/curry/\"},{\"text\":\"identity\",\"link\":\"/fn/identity/\"},{\"text\":\"once\",\"link\":\"/fn/once/\"},{\"text\":\"pipe\",\"link\":\"/fn/pipe/\"}]},{\"text\":\"Object\",\"collapsed\":false,\"items\":[{\"text\":\"prop\",\"link\":\"/fn/prop/\"}]},{\"text\":\"List\",\"collapsed\":false,\"items\":[{\"text\":\"at\",\"link\":\"/fn/at/\"},{\"text\":\"concatMap\",\"link\":\"/fn/concatMap/\"},{\"text\":\"isIterable\",\"link\":\"/fn/isIterable/\"},{\"text\":\"iterative\",\"link\":\"/fn/iterative/\"},{\"text\":\"last\",\"link\":\"/fn/last/\"},{\"text\":\"toArray\",\"link\":\"/fn/toArray/\"},{\"text\":\"treeEach\",\"link\":\"/fn/treeEach/\"},{\"text\":\"unique\",\"link\":\"/fn/unique/\"},{\"text\":\"zip\",\"link\":\"/fn/zip/\"},{\"text\":\"zipWith\",\"link\":\"/fn/zipWith/\"}]},{\"text\":\"Math\",\"collapsed\":false,\"items\":[{\"text\":\"clamp\",\"link\":\"/fn/clamp/\"},{\"text\":\"decimalLength\",\"link\":\"/fn/decimalLength/\"},{\"text\":\"isSafeNum\",\"link\":\"/fn/isSafeNum/\"},{\"text\":\"splitIntegerDecimal\",\"link\":\"/fn/splitIntegerDecimal/\"},{\"text\":\"toNumberStr\",\"link\":\"/fn/toNumberStr/\"}]},{\"text\":\"Logic\",\"collapsed\":false,\"items\":[{\"text\":\"and\",\"link\":\"/fn/and/\"},{\"text\":\"ifElse\",\"link\":\"/fn/ifElse/\"},{\"text\":\"isEmpty\",\"link\":\"/fn/isEmpty/\"},{\"text\":\"or\",\"link\":\"/fn/or/\"}]},{\"text\":\"Type\",\"collapsed\":false,\"items\":[{\"text\":\"isExist\",\"link\":\"/fn/isExist/\"},{\"text\":\"isIterable\",\"link\":\"/fn/isIterable/\"},{\"text\":\"isNil\",\"link\":\"/fn/isNil/\"},{\"text\":\"typeOf\",\"link\":\"/fn/typeOf/\"}]},{\"text\":\"DOM\",\"collapsed\":false,\"items\":[{\"text\":\"getPoint\",\"link\":\"/fn/getPoint/\"},{\"text\":\"matrixTo\",\"link\":\"/fn/matrixTo/\"}]},{\"text\":\"Utils\",\"collapsed\":false,\"items\":[{\"text\":\"debounce\",\"link\":\"/fn/debounce/\"},{\"text\":\"promiseTry\",\"link\":\"/fn/promiseTry/\"},{\"text\":\"sleep\",\"link\":\"/fn/sleep/\"},{\"text\":\"throttle\",\"link\":\"/fn/throttle/\"},{\"text\":\"toPromiseTuple\",\"link\":\"/fn/toPromiseTuple/\"},{\"text\":\"toggle\",\"link\":\"/fn/toggle/\"}]}]},\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/varcat/toolkit_js\"}]},\"locales\":{},\"scrollOffset\":134,\"cleanUrls\":false}");</script>
    
  </body>
</html>